// ^2_3^
import request from '@/utils/request'

const userApi = {
  /// 登录
  // Login: '/auth/login',
  Login: '/admin/login',
  /// 登出
  // Logout: '/auth/logout',
  Logout: '/admin/logout',
  ForgePassword: '/auth/forge-password',
  Register: '/auth/register',
  twoStepCode: '/auth/2step-code',
  SendSms: '/account/sms',
  SendSmsErr: '/account/sms_err',
  /// ^2_3^获取用户信息
  // UserInfo: '/user/info',
  UserInfo: '/admin/info',
  // ^2_3^ 用户菜单
  // UserMenu: '/user/nav'
  UserMenu: '/admin/navigation'
}

/**
 * ^2_3^ login func
 * parameter: {
 *     username: '',
 *     password: '',
 *     remember_me: true,
 *     captcha: '12345'
 * }
 * @param parameter
 * @returns {*}
 */
export function login (parameter) {
  console.log('>login fn(parameter)', parameter)
  const result = request({
    baseURL: process.env.VUE_APP_API_BASE_URL_SET,
    url: userApi.Login,
    method: 'post',
    data: parameter
  })
  console.log('>login result', result)
  return result
}

/**
 * ^2_3^ getSmsCaptcha
 * @param {Object} parameter
 */
export function getSmsCaptcha (parameter) {
  return request({
    url: userApi.SendSms,
    method: 'post',
    data: parameter
  })
}

// ^2_3^获取用户信息
export function getInfo () {
  return request({
    baseURL: process.env.VUE_APP_API_BASE_URL_SET,
    url: userApi.UserInfo,
    method: 'get',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    }
  })
}

// ^2_3^当前用户菜单导航
export function getCurrentUserNav () {
  return request({
    baseURL: process.env.VUE_APP_API_BASE_URL_SET,
    url: userApi.UserMenu,
    method: 'get'
  })
}

// ^2_3^
export function logout () {
  return request({
    baseURL: process.env.VUE_APP_API_BASE_URL_SET,
    url: userApi.Logout,
    method: 'post',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    }
  })
}

/**
 * ^2_3^ get user 2step code open?
 * @param parameter {*}
 */
export function get2step (parameter) {
  return request({
    url: userApi.twoStepCode,
    method: 'post',
    data: parameter
  })
}
